﻿using System;
using System.Collections.Generic;
using System.Data;

using RexToy.ORM;

namespace Studio.Model
{
    class SQLServerModel : DatabaseModel
    {
        public SQLServerModel()
        {
            _server = ".";
            _username = "sa";
            _password = "123";
        }

        public override string ConnectString
        {
            get
            {
                if (_integratedSecurity)
                {
                    return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=true;", _server, _schema);
                }
                else
                {
                    return string.Format("server={0};database={1};uid={2};pwd={3};", _server, _schema, _username, _password);
                }
            }
        }

        public override string Dialect
        {
            get { return RexToy.ORM.Session.Dialect.MSSQL; }
        }

        public override string Provider
        {
            get { return null; }
        }

        public override string DialectProvider
        {
            get { return null; }
        }

        public override void ReadModel()
        {
            using (var db = DatabaseFactory.OpenDatabase())
            {
                _tables = db.QueryMeta().Tables;
            }
        }
    }
}
